package com.blt.car.me;

import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.blt.car.R;
import com.blt.car.base.BaseTitleBarActivity;
import com.blt.car.base.ViewHolder;
import com.blt.car.me.adapter.RedAdapter;
import com.blt.car.widget.dialog.TakeCashDialog;

import java.text.DecimalFormat;
import java.util.List;

import blt.app_core.api.base.CoreEvent;
import blt.app_core.api.base.CoreManager;
import blt.app_core.api.journey.bean.AppealInfo;
import blt.app_core.api.purse.PayApi;

/**
 * Created by xgp
 * on 2017/6/27.
 */

public class MyRedActivity extends BaseTitleBarActivity {

    public static final String RED_AMT = "red_amt";
    private String redAmount;

    private TextView tvAmount;
//    private TextView tvJourneyAmount;
//    private TextView tvExtractAmount;
//    private TextView tvJourneyTime;
//    private TextView tvExtractTime;

    private ListView mListview;

    private RedAdapter redAdapter;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_red_package;
    }


    @Override
    protected void initData() {
        super.initData();
        redAmount = getIntent().getExtras().getString(RED_AMT);
        CoreManager.getCore(PayApi.class).getRedInfo();
    }

    @Override
    protected void initView(ViewHolder holder) {
        mTitleBar.setTitle("我的红包");
        tvAmount = holder.get(R.id.red_tv_amount);
        mListview = holder.get(R.id.red_listview);
        redAdapter = new RedAdapter(this, R.layout.item_red_extract);
        mListview.setAdapter(redAdapter);
        tvAmount.setText(redAmount + "元");
    }

    public void getCash(View view) {//提现
        if (Float.valueOf(redAmount) < 10) {
            toastShort("红包少于10元无法提现");
            return;
        }
        TakeCashDialog takeCashDialog = new TakeCashDialog(this);
        takeCashDialog.show();
    }

    @CoreEvent(coreClientClass = PayApi.class)
    public void onRedInfo(List<AppealInfo> data) {
        redAdapter.addData(data);
    }

    @CoreEvent(coreClientClass = PayApi.class)
    public void onExtract(String amount) {
        toastShort("提现成功");
        float newAmount=Float.valueOf(redAmount)-Float.valueOf(amount);
        DecimalFormat de=new DecimalFormat("0.00");
        redAmount=de.format(newAmount);
        tvAmount.setText(redAmount+"元");
    }
}
